package com.douguo.recipe.sina;

import android.util.Log;

public class CacheEntity implements Comparable<CacheEntity>{

	public String key;
	private Object cache;
	public long lastVisitTime;
	public int visitCount;
	
	public CacheEntity(String key, Object obj){
		cache = obj;
		this.key = key;
		visitCount++;
	}
	
	public Object getObject(){
		visitCount++;
		lastVisitTime = System.currentTimeMillis();
		return cache;
	}
	
	@Override
	public int compareTo(CacheEntity another) {
		Log.d("UMessage", "compareTo : ");
		if (another.lastVisitTime < lastVisitTime && another.visitCount < visitCount ){
			return 1;
		}
		if (Math.abs(another.lastVisitTime - lastVisitTime) > 1000 * 60 * 60){
			return another.lastVisitTime > lastVisitTime ? -1 : 1;
		}		
		return another.visitCount > visitCount ? -1 : 1;
	}
}
